package com.chinaunicom.emergency.service;

import com.chinaunicom.emergency.model.AccReport;
import com.chinaunicom.emergency.repository.AccReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author liuzhuang
 * @date 2020-8-5
 */
@Service
public class AccReportService  {
    @Autowired
    private AccReportRepository accReportRepository;
    
    public AccReport get(String id) {
        Optional<AccReport> optional = accReportRepository.findById(id);
        if (optional.isPresent()) {
            return optional.get();
        } else {
            return null;
        }
    }
    
    public List<AccReport> findAllList() {
        return accReportRepository.findAll();
    }
    
    public AccReport insert(AccReport accReport) {
        accReport.setCreateTime(new Date());
        return accReportRepository.save(accReport);
    }
    
    public List<AccReport> insertBatch(List<AccReport> accReports) {
        return accReportRepository.saveAll(accReports);
    }
    
    public AccReport update(AccReport accReport) {
        accReport.setUpdateTime(new Date());
        return accReportRepository.save(accReport);
    }
    
    public void delete(AccReport accReport) {
        accReportRepository.delete(accReport);
    }

}
